
macro FastProcEnter a
{
   match any, a
   \{
      push a
      mov  a, rsp
   \}
   match , a
   \{
      push rbp
      mov  rbp, rsp
   \}
}

macro FastProcLeave a
{
   match any, a
   \{
      mov rsp, a
      pop a
   \}
   match , a
   \{
      leave
   \}
}

macro AlignProcEnter a, b, s
{
   local loc,n,drap,sd
   n = 8
   sd = s

   drap equ a

   match =push d, a
   \{
      drap equ d
      n = 16
   \}
   match =pushn d, a
   \{
      drap equ d
      n = 16
      sd = 0
   \}

   if s
      if sd
	 loc = -8
      else
	 loc = 0
      end if
      if n = 16
	 push drap
      end if
      lea drap, [rsp+n]
      and rsp, -s
      push dword [drap-8]
   else
      loc = 0
   end if

   push rbp
   mov	rbp, rsp

   if sd
      push drap
   end if
   irps c, b
   \{
      \forward
      push c
      loc = loc-8
   \}

   local_fp equ (rbp+loc)

   macro .base@AlignProcLeave d
   \{
       match any, d \\{ r equ d \\}
       match , d \\{ r equ drap \\}

       if loc
	  lea rsp, [rbp+loc]
	  irps c, b
	  \\{
	     \\reverse
	     pop c
	  \\}
	  if sd
	     pop r
	  end if

	  pop rbp
       else
	  leave
       end if

       if s
	  lea rsp, [r-n]
	  if n = 16
	     pop drap
	  end if
       end if
       restore local_fp
       restore drap
       restore r
   \}
}

macro AlignProcLeave a
{
   .base@AlignProcLeave a
   purge .base@AlignProcLeave
}

macro ._until a, b
{
   dec	 a
   match any, b \{
      .until ZERO? & (b)
   \}
   match , b \{
      .until ZERO?
   \}
}

macro movstr r, s
{
   local   .a
   call    .a
   db	   s, 0
.a:
   pop	   r
}
